package com.bw.module_mine.ui.mine.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_mine.R
import com.bw.module_mine.databinding.LayoutToolsItemBinding
import com.bw.module_mine.model.TabItem

/**
 * @author zhy
 * @date 2025-09-22 15:46
 * @description
 */
class ToolAdapter(
    private val mList: List<TabItem>,
    private val mOnItemClickListener: (TabItem) -> Unit
): RecyclerView.Adapter<ToolAdapter.ToolViewHolder>() {
    class ToolViewHolder(val binding: LayoutToolsItemBinding):RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ToolViewHolder {
        val binding = DataBindingUtil.inflate<LayoutToolsItemBinding>(LayoutInflater.from(parent.context), R.layout.layout_tools_item, parent, false)
        return ToolViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ToolViewHolder, position: Int) {
        //绑定数据
        holder.binding.apply {
            item = mList[position]
        }
        //点击事件
        holder.binding.lTab.setOnClickListener{
            mOnItemClickListener.invoke(mList[position])
        }
    }


}